<?php

namespace App\Http\Controllers\Admin;

use App\Models\Notice;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class NoticeController extends Controller
{
    //预约列表
    public function index()
    {
        $data = Notice::with('owner')->get();
        return view('admin.notice.index',compact('data'));
    }

    //添加预约 显示
    public function create()
    {
        return view('admin.notice.create');
    }

    //添加预约 处理
    public function store(Request $request)
    {
        try {
            $this->validate($request,[
                'fangowner_id' => 'required',
                'renting_id' => 'required',
                'cnt' => 'required'
            ]);
        }catch (\Exception $exception){
            return ['status'=>1000,'msg'=>'添加失败'];
        }

        $postData = $request->except(['_token']);
        Notice::create($postData);
        return ['status'=>0,'msg'=>'添加成功'];
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Notice  $notice
     * @return \Illuminate\Http\Response
     */
    public function show(Notice $notice)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Notice  $notice
     * @return \Illuminate\Http\Response
     */
    public function edit(Notice $notice)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Notice  $notice
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Notice $notice)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Notice  $notice
     * @return \Illuminate\Http\Response
     */
    public function destroy(Notice $notice)
    {
        $notice->delete();
        return ['status'=>0,'msg'=>'删除成功'];
    }
}
